package com.togo.algorithm.easy.math;

/**
 * @Author taiyn
 * @Description TODO
 * @Date 下午11:11 2022/4/11
 **/
public class No415 {

    public String addStrings(String num1, String num2) {

        int l1 = num1.length() - 1;
        int l2 = num2.length() - 1;

        int r = 0;
        StringBuilder sb = new StringBuilder();
        while(l1 > -1 && l2 > -1) {
            int sum = num1.charAt(l1) - '0' + num2.charAt(l2) - '0' + r;
            r = sum / 10;
            sb.append(sum % 10);
            l1--;
            l2--;
        }

        while(l1 > -1) {
            if(r > 0) {
                int sum = num1.charAt(l1) - '0' + r;
                r = sum / 10;
                sb.append(sum % 10);
            } else {
                sb.append(num1.charAt(l1) - '0');
            }
            l1--;
        }

        while(l2 > -1) {
            if(r > 0) {
                int sum = num2.charAt(l2) - '0' + r;
                r = sum / 10;
                sb.append(sum % 10);
            } else {
                sb.append(num2.charAt(l2) - '0');
            }
            l2--;
        }

        if(r > 0) sb.append(r);

        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        No415 no415 = new No415();
        no415.addStrings("9133","0");
    }
}
